// 用户账号表User

import { Entity, PrimaryColumn, Column, OneToMany } from 'typeorm';
import { AuthorizationCode } from './AuthorizationCode';
import { AccessToken } from './Accesstoken';
import {Device} from "./Device";
import { DeviceGroup } from './DeviceGroup';

@Entity()
export class User {

  @PrimaryColumn({
      type: 'varchar',
      length: '255'
  })
  userId!: string;

  @Column({
      type: 'varchar',
      length: '255'
  })
  password!: string;


  // 设备管理表一对多关系
  @OneToMany(() => Device, device => device.user)
  devices!: Device[]; // 用户的设备列表
  // 设备分组表一对多
  @OneToMany(() => DeviceGroup, group => group.user)
  deviceGroups!: DeviceGroup[];


  // 第三方相关外键
  @OneToMany(() => AuthorizationCode, code => code.user)
  authorizationCodes!: AuthorizationCode[];

  @OneToMany(() => AccessToken, token => token.user)
  accessTokens!: AccessToken[]; // 用户的第三方平台授权列表

}
